package com.sky.controller.User;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/shoppingCart")
@Slf4j
@Api("购物车")
public class ShopCartController {


    @Autowired
    private ShoppingCartService shoppingCartService;

    @PostMapping("/add")
    public Result addToShopCart(@RequestBody ShoppingCartDTO kkk){

        shoppingCartService.addToShopCart(kkk);
        return Result.success();
    }

    @DeleteMapping("/clean")
    public Result cleanShopCart(){
        shoppingCartService.cleanShopCart();
        return Result.success();
    }
    @PostMapping("/sub")
    public Result subObjShoppingCart(@RequestBody ShoppingCartDTO kkk){
        shoppingCartService.subObjShoppingCart(kkk);
        return Result.success();
    }

    @GetMapping("/list")
    public Result<List<ShoppingCart>> listShoppingCart(){
        List<ShoppingCart> kks = shoppingCartService.getListShoppingCart();
        return Result.success(kks);
    }


}
